﻿@using System.Collections.Concurrent
@model HotelManageSystem.Models.AttendanceModel
<script src="@Url.Content("~/Scripts/jquery-1.7.1.min.js")" type="text/javascript"> </script>
<script src="@Url.Content("~/Scripts/jquery.validate.min.js")" type="text/javascript"> </script>
<script src="@Url.Content("~/Scripts/jquery.validate.unobtrusive.min.js")" type="text/javascript"> </script>
<link href= "@Url.Content("~/Content/TelerikGrid.css")"rel="stylesheet" type="text/css" />
<style>
    select
    {
        height: 24px;
        width: 90%;
    }
    input
    {
        height: 23px;
        width: 90%;
    }
    textarea
    {
        max-width: 90%;
        max-height: 70px;
        min-width: 90%;
        min-height: 70px;
        resize: none;
    }
</style>
<script type="text/javascript">
    $(document).ready(function () {
        //让员工信息只读
        $("#EmployeeId").attr("readonly", "readonly");
        $("#Name").attr("readonly", "readonly");
        //让日期选择文本框只读
        $(".t-picker-wrap>input").first().attr("readonly", "readonly");

        //点击返回按钮要将Attendance/InsertIndex加载到content当中来
        //然后设置菜单session为Attendance/InsertIndex
        $("#return").click(function () {
            $.get("Attendance/InsertIndex", null, function (data) {
                $("#content").html(data);
            });
            $.post("HumanResources/SetSeesion", { u: "Attendance/InsertIndex" }, function () { });
        });

        //在考勤状态中,如果是请假等情况则将日期文本框设为不可用,并将时间设为0：00
        $("#AttendaceStatus").change(function () {
            var v = $(this).attr("value");
            if (v == "正常" | v == "迟到" | v == "早退") {
                $(".t-select").removeAttr("style");
                $(".t-picker-wrap>input").removeattr("readonly");
                $(".t-picker-wrap>input").first().attr("readonly", "readonly");
            }
            else {
                $("#StartTime").attr("value", "0:00");
                $("#EndTime").attr("value", "0:00");
                $(".t-picker-wrap>input").attr("readonly", "readonly");
                $(".t-select").attr("style", "display:none");
                $(".t-select").first().removeAttr("style");
            }
        });
    });
    //表单提交时验证这条考勤信息是否添加过,也就是该员工当天的考勤信息是否添加到数据库当中
    function onClick() {
        var id = $("#EmployeeId").attr("value");
        var attendDate = $("#AttendDate").attr("value");
        var v;
        $.ajax({
            url: '/Attendance/CheckIn',
            async: false,
            type: 'POST',
            data: { id: id, attendDate: attendDate },
            dataType: 'json',
            success: function (data) {
                v = data.Data.Value;
            }
        });
        if (v == "false") {
            alert("每位员工当天只能添加一条考勤记录\r\n如果有疑问请先将当前考勤数据删除");
            return false;
        }
        return true;
    }
</script>
<div class="t-widget t-grid" style="width: 100%; height: 100%">
    @using (Html.BeginForm("Insert", "Attendance", FormMethod.Post))
    {
        @Html.ValidationSummary(true)
        <div class="t-edit-form-container" style="width: 100%;">
            <fieldset style="width: 100%; border: 0px;">
                <legend style="font-size: 20px;">新增考勤：</legend>
                <table>
                    <tr>
                        <td>
                            <div class="editor-label">
                                @Html.LabelFor(model => model.EmployeeId)
                            </div>
                            <div class="editor-field">
                                @Html.EditorFor(model => model.EmployeeId)
                                @Html.ValidationMessageFor(model => model.EmployeeId)
                            </div>
                        </td>
                        <td>
                            <div class="editor-label">
                                @Html.LabelFor(model => model.Name)
                            </div>
                            <div class="editor-field">
                                @Html.EditorFor(model => model.Name)
                                @Html.ValidationMessageFor(model => model.Name)
                            </div>
                        </td>
                    </tr>
                    <tr>
                        <td>
                            <div class="editor-label">
                                @Html.LabelFor(model => model.AttendDate)
                            </div>
                            <div class="editor-field">
                                @Html.EditorFor(model => model.AttendDate)
                                @Html.ValidationMessageFor(model => model.AttendDate)
                            </div>
                        </td>
                        <td>
                            <div class="editor-label">
                                @Html.LabelFor(model => model.StartTime)
                            </div>
                            <div class="editor-field">
                                @Html.EditorFor(model => model.StartTime)
                                @Html.ValidationMessageFor(model => model.StartTime)
                            </div>
                        </td>
                    </tr>
                    <tr>
                        <td>
                            <div class="editor-label">
                                @Html.LabelFor(model => model.EndTime)
                            </div>
                            <div class="editor-field">
                                @Html.EditorFor(model => model.EndTime)
                                @Html.ValidationMessageFor(model => model.EndTime)
                            </div>
                        </td>
                        <td>
                            <div class="editor-label">
                                @Html.LabelFor(model => model.AttendaceStatus)
                            </div>
                            <div class="editor-field">
                                @Html.DropDownListFor(model => model.AttendaceStatus, new[]
                                                                {
                                                                    new SelectListItem() {Text="正常",Value="正常"},
                                                                    new SelectListItem() {Text="迟到",Value="迟到"}, 
                                                                    new SelectListItem() {Text="早退",Value="早退"}, 
                                                                    new SelectListItem() {Text="旷工",Value="旷工"},
                                                                    new SelectListItem() {Text="请假",Value="请假"}, 
                                                                    new SelectListItem() {Text="调休",Value="调休"},
                                                                    new SelectListItem() {Text="出差",Value="出差"} 
                                                                })
                                @Html.ValidationMessageFor(model => model.AttendaceStatus)
                            </div>
                        </td>
                    </tr>
                    <tr>
                        <td>
                            <div class="editor-label">
                                @Html.LabelFor(model => model.AttendaceRemark)
                            </div>
                            <div class="editor-field">
                                @Html.TextAreaFor(model => model.AttendaceRemark)
                                @Html.ValidationMessageFor(model => model.AttendaceRemark)
                            </div>
                        </td>
                    </tr>
                </table>
                <p>
                    <input type="submit" value="提交" onclick="return onClick()" style="height: 23px; width: 5%;" />
                    <input type="button" value="返回" id="return" style="height: 23px; width: 5%;" />
                </p>
            </fieldset>
        </div>
    }
</div>
